﻿using System;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Configuration;

using SBPweb.PROvibe.Server.Framework.Content;
using SBPweb.PROvibe.Server.Framework.Communication;

namespace SBPweb.PROvibe.Server.Host.Services
{

    public class ContentProviderFactory : BasicServiceHostFactory<ContentProvider, IContentProvider>
    {
    }
    /*
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    [ServiceContract(Namespace = "SBPweb.PROvibe.Server", SessionMode = SessionMode.Allowed)]
    public class ContentProvider : Framework.Content.ContentProviderBase
    {

        #region TypeDescriptor related

        [OperationContract(IsOneWay = false)]
        public override int GetCurrentPageId(ClientDescriptor clientDescriptor)
        {
            return base.GetCurrentPageId(clientDescriptor);
        }

        [OperationContract(IsOneWay = false)]
        public override int GetCurrentThemeManagerId(ClientDescriptor clientDescriptor)
        {
            return base.GetCurrentThemeManagerId(clientDescriptor);
        }

        [OperationContract(IsOneWay = false)]
        public override TypeDescriptor GetTypeDescriptorById(int smartpartId)
        {
            return base.GetTypeDescriptorById(smartpartId);
        }

        #endregion

        #region Session related

        [OperationContract(IsOneWay = false)]
        public override void AddSessionBagItem(ClientDescriptor clientDescriptor, string key, object value)
        {
            base.AddSessionBagItem(clientDescriptor, key, value);
        }

        [OperationContract(IsOneWay = false)]
        public override void ChangeSessionBagItem(ClientDescriptor clientDescriptor, string key, object newValue)
        {
            base.ChangeSessionBagItem(clientDescriptor, key, newValue);
        }

        [OperationContract(IsOneWay = false)]
        public override void RemoveSessionBagItem(ClientDescriptor clientDescriptor, string key)
        {
            base.RemoveSessionBagItem(clientDescriptor, key);
        }

        [OperationContract(IsOneWay = false)]
        public override IDictionary<string, object> GetFullSessionBag(ClientDescriptor clientDescriptor)
        {
            return base.GetFullSessionBag(clientDescriptor);
        }

        [OperationContract(IsOneWay = false)]
        public override void PutFullSessionBag(ClientDescriptor clientDescriptor, IDictionary<string, object> values)
        {
            base.PutFullSessionBag(clientDescriptor, values);
        }

        #endregion

    }

    public class CustomHostFactory : ServiceHostFactoryBase
    {

        public CustomHostFactory()
            : base()
        {
        }

        public override ServiceHostBase CreateServiceHost(string constructorString, Uri[] baseAddresses)
        {
            Uri baseAddress = baseAddresses[0];
            string dnsSafeHost = ConfigurationManager.AppSettings["dnsSafeHost"];
            if (!string.IsNullOrEmpty(dnsSafeHost))
            {
                foreach (Uri uri in baseAddresses)
                {
                    if (dnsSafeHost == uri.DnsSafeHost)
                    {
                        baseAddress = uri;
                        break;
                    }
                }
            }
            CustomHost customServiceHost = new CustomHost(typeof(ContentProvider), baseAddress);
            return customServiceHost;
        }
    }

    public class CustomHost : ServiceHost
    {

        public CustomHost(Type serviceType, params Uri[] baseAddresses)
            : base(serviceType, baseAddresses)
        {
        }

        protected override void ApplyConfiguration()
        {
            base.ApplyConfiguration();
        }

    }
    */
}